/* header 登录转换 */
let uidn = localStorage.getItem('uid');
if (uidn != null) {
    let username = localStorage.getItem('username');
    $('#login').html(username).click(function(){
        var userRes = confirm('是否要退出登录');
        if(userRes == true){
            localStorage.removeItem('uid');
            localStorage.removeItem('username');
            location.href = './login.html';
        }
    })
}else{
    $('#login').html('登录').click(function(){
        location.href = './login.html'
    })
}


/* nav下拉跳转 */
$("#nav div ul").on('click','li', function () {
    localStorage.setItem('pclass', $(this).attr('pclass'));
    localStorage.setItem('pid', $(this).attr('pid'));
    location.href = './infor.html';
    console.log(11)
})

$('[type=submit]').click(function () {
    let username = $('form #username').val();
    let password = $('form #password').val();
    var flag = false;
    axios.get('http://localhost:3000/users')
        .then(function (res) {
            res.data.forEach(v => {
                if (v.username == username && v.password == password) {
                    flag = true;
                    localStorage.setItem('username', v.username);
                    localStorage.setItem('uid', v.id);
                    var res = confirm('登录成功!是否要跳回首页');
                    if(res == true){
                        location.href = '../index.html';
                    }else{
                        location.href = '../pages/login.html';
                    }
                }
            });
            if (flag == false) {
                alert('用户名或密码错误!')
            }
        })
})

